<template>
    <div class="debris-list" v-loading="loading">
        <div class="loading-wrap" v-if="refrashLoading" v-loading="refrashLoading"></div>
        <div class="input-box">
            <span class="input-title">关键字</span>
            <el-input
                placeholder="搜索皮肤名或英雄名"
                @keyup.enter.native="selectChange"
                style="width:220px;"
                clearable
                v-model.trim="paramsList.keyWord">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>

            <!-- <span class="input-title" style="margin-left: 20px;">估值标签</span>
            <el-input
                placeholder="请输入估值标签"
                @keyup.enter.native="selectChange"
                style="width:196px;"
                clearable
                v-model.trim="paramsList.worthLabel">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input> -->

            <el-button type="primary" class="btn" style="margin-left:10px" @click="getList(1)">查询</el-button>
            <el-button type="success" class="btn" style="margin-left:10px" @click="toDetail">新建星传说皮肤</el-button>
            <el-button type="warning" class="btn" style="margin-left:10px" @click="ref">抓取非星传说皮肤</el-button>
        </div>

        <div class="input-box">
            <span class="input-title">职业</span>
            <el-select @change="getList(1, 10)" style="width:120px;" v-model="paramsList.careerId">
                <el-option :label="item.careerName" :value="item.careerId" v-for="(item, index) in zhiyeList" :key="index"></el-option>
            </el-select>

            <span class="input-title" style="margin-left: 20px;">限定类型</span>
            <el-select @change="getList(1, 10)" style="width:120px;" v-model="paramsList.limitType">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="非限定" :value="0"></el-option>
                <el-option label="典藏限定" :value="1"></el-option>
                <el-option label="热门限定" :value="2"></el-option>
                <el-option label="普通限定" :value="3"></el-option>
            </el-select>

            <span class="input-title" style="margin-left: 20px;">必选类型</span>
            <el-select @change="getList(1, 10)" style="width:120px;" v-model="paramsList.required">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="非必选" :value="0"></el-option>
                <el-option label="必选" :value="1"></el-option>
            </el-select>

            <span class="input-title" style="margin-left: 20px;">APP展示标签</span>
            <el-select @change="getList(1, 10)" style="width:120px;" v-model="paramsList.labelName">
                <el-option :label="item.labelName" :value="item.labelName" v-for="(item, index) in labelList" :key="index"></el-option>
            </el-select>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" @sort-change="sortChange" border style="width: 100%">
                <el-table-column width="80" prop="orderNo" label="职业">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.tradeWzryCareerList" :key="index">
                            <span v-if="index === 0">{{ item.careerName }}</span>
                            <span v-else>,{{ item.careerName }}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column width="120" prop="heroName" label="英雄名"></el-table-column>
                <el-table-column min-width="120" prop="name" label="皮肤名"></el-table-column>
                <!-- <el-table-column min-width="120" label="限定类型">
                    <template slot-scope="scope">
                        <p v-if="scope.row.limitType === 0">非限定</p>
                        <p v-if="scope.row.limitType === 1">典藏</p>
                        <p v-if="scope.row.limitType === 2">热门限定</p>
                        <p v-if="scope.row.limitType === 3">普通限定</p>
                    </template>
                </el-table-column> -->
                <el-table-column min-width="120" sortable="custom" label="估值" prop="coupon"></el-table-column>
                <!-- <el-table-column min-width="120" label="英雄点券价格" prop="couponNum"></el-table-column> -->
                <!-- <el-table-column min-width="120" label="英雄钻石价格" prop="diamonNum"></el-table-column> -->
                <el-table-column min-width="120" label="英雄金币价格" prop="coinNum"></el-table-column>
                <el-table-column min-width="150" label="趣宝石数量" prop="diamond"></el-table-column>
                <el-table-column width="100" label="必选类型">
                    <template slot-scope="scope">
                        <p v-if="scope.row.required === 0">非必选</p>
                        <p v-if="scope.row.required === 1">必选</p>
                    </template>
                </el-table-column>
                <el-table-column min-width="120" label="APP展示标签">
                    <template slot-scope="scope">
                        <div>{{ scope.row.labelName || '-' }}</div>
                    </template>
                </el-table-column>
                <!-- <el-table-column min-width="100" label="估值标签" prop="worthLabel">
                    <template slot-scope="scope">
                        <div>{{ scope.row.worthLabel || '-' }}</div>
                    </template>
                </el-table-column> -->
                <el-table-column width="120" label="英雄图片">
                    <template slot-scope="scope">
                        <imgBox :url="scope.row.heroIcon"/>
                    </template>
                </el-table-column>
                <el-table-column width="120" label="皮肤图片">
                    <template slot-scope="scope">
                        <imgBox :url="scope.row.icon"/>
                    </template>
                </el-table-column>
                <el-table-column width="120" label="皮肤长图">
                    <template slot-scope="scope">
                        <imgBox v-if="scope.row.verticalPic" :url="scope.row.verticalPic"/>
                        <span v-else>暂无</span>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="toDetail(scope.row)" style="margin-left: 10px;" type="text" size="small">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data () {
        return {
            paramsList: {
                keyWord: null, // 关键字
                careerId: null, // 职业
                limitType: null, // 限定类型0非限定1典藏2热限3普限
                required: null, // 必选类型
                labelName: '全部', // App展示标签
                worthLabel: '' // 估值标签
            },
            params: { // 当前接口请求参数（用于缓存）
                keyWord: null, // 关键字
                careerId: null, // 职业
                limitType: null, // 限定类型0非限定1典藏2热限3普限
                required: null, // 必选类型
                labelName: '全部', // App展示标签
                worthLabel: '' // 估值标签
            },
            tableData: [],
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0,
            loading: false,
            labelList: [
                {
                    labelName: '全部'
                }
            ], // App展示标签
            zhiyeList: [ // 职业
                {
                    careerId: null,
                    careerName: '全部'
                },
                {
                    careerId: 100,
                    careerName: '坦克'
                },
                {
                    careerId: 101,
                    careerName: '战士'
                },
                {
                    careerId: 102,
                    careerName: '刺客'
                },
                {
                    careerId: 103,
                    careerName: '法师'
                },
                {
                    careerId: 104,
                    careerName: '射手'
                },
                {
                    careerId: 105,
                    careerName: '辅助'
                }
            ],
            refrashLoading: false,
            type: '',
            sort: ''
        }
    },
    activated () {
        this.paramsList = { ...this.params }
        if (this.paramsList.labelName === null) {
            this.paramsList.labelName = '全部'
        }
        this.getList(this.pageNum)
        this.getLabel()
    },
    methods: {
        // 获取lable标签
        getLabel () {
            this.labelList = [
                {
                    labelName: '全部'
                }
            ]
            this.$http.get('/trade/selectTradeWZRYLabel').then(res => {
                if (res.code === '0') {
                    this.labelList.push(...res.data)
                } else {
                    this.$message({
                        type: 'error',
                        message: '系统异常，请稍后再试'
                    })
                }
            })
        },

        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            this.params = {
                pageNum: pageNum,
                pageSize: this.pageSize,
                type: this.type,
                sort: this.sort
            }
            this.params = Object.assign(this.params, this.paramsList)

            if (this.params.labelName === '全部') {
                this.params.labelName = null
            }
            let res = await this.$http.get('/trade/selectWZRYSkin', {
                params: this.params
            })
            if (res.code === '0') {
                this.tableData = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        // 后端排序
        sortChange ({ column, prop, order }) {
            this.sort = order || ''
            // 如果没有 sort prop 置为空
            if (this.sort === 'ascending') {
                this.sort = 'asc'
            } else {
                this.sort = 'desc'
            }
            this.type = prop
            this.getList(1)
        },
        ref () {
            this.refrashLoading = true
            let mainDom = document.getElementsByClassName('main')[0]
            mainDom.style.overflow = 'hidden'
            axios.get('https://api-game.duodian.cn/api/trade/refreshHeroSkin').then(res => {
                this.refrashLoading = false
                mainDom.style.overflow = 'auto'
                if (res.code === '0') {
                    this.$message({
                        type: 'success',
                        message: '刷新成功'
                    })
                    this.getList(1)
                } else {
                    this.$message({
                        type: 'error',
                        message: '系统异常，请稍后再试'
                    })
                }
            }).catch(() => {
                this.refrashLoading = false
                mainDom.style.overflow = 'auto'
            })
        },
        selectChange () {
            this.type = ''
            this.sort = ''
            this.$refs.table.clearSort()
            this.getList(1)
        },
        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },
        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        },
        toDetail (item) {
            let query = null
            if (item) {
                query = {
                    skinId: item.id
                }
            }
            const { href } = this.$router.resolve({
                path: `/wzry/skinDetail`,
                query
            })
            window.open(href, '_blank')
        }
    }
}
</script>

<style lang="scss" scoped>
    .debris-list {
        position: relative;
        .loading-wrap {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            min-height: 100vh;
        }
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin-right: 10px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }

        .table-box {
            margin: 20px 0;
            .cover {
                width: 80px;
                height: 80px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
            .desc {
                overflow: hidden;
                line-height: 20px;
                -webkit-line-clamp: 5;
                -webkit-box-orient: vertical;
                display: -webkit-box;
                height: 100px;
            }
            .hero-icon {
                width: 100px;
                height: 100px;
            }
            .vertical-icon {
                width: 128px;
                height: 188px;
            }
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
            .point {
                display:inline-block;
                width:10px;
                height:10px;
                border-radius: 50%;
                background-color:#67C23A;
                margin-right:3px;
            }
            .red-point {
                background-color: #F56C6C;
            }
        }

        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
        .dialog-reason {
            margin-top: 20px;
            p {
                margin-bottom: 10px;
            }
        }
    }
</style>
